//add by wangjun
package calc

import "github.com/alfredxing/calc/operators"

var (
	and = &operators.Operator{
		Name:          "&&",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if int(args[0]) != 0 && int(args[1]) != 0 {
				return 1
			}
			return 0
		},
	}
	or = &operators.Operator{
		Name:          "||",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if int(args[0]) != 0 || int(args[1]) != 0 {
				return 1
			}
			return 0
		},
	}
	bitAnd = &operators.Operator{
		Name:          "&",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			return float64(int(args[0]) & int(args[1]))
		},
	}
	bitOr = &operators.Operator{
		Name:          "|",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			return float64(int(args[0]) | int(args[1]))
		},
	}

	lt = &operators.Operator{
		Name:          "<",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if args[0] < args[1] {
				return 1
			}
			return 0
		},
	}
	le = &operators.Operator{
		Name:          "<=",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if args[0] <= args[1] {
				return 1
			}
			return 0
		},
	}

	gt = &operators.Operator{
		Name:          ">",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if args[0] > args[1] {
				return 1
			}
			return 0
		},
	}
	ge = &operators.Operator{
		Name:          ">=",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if args[0] >= args[1] {
				return 1
			}
			return 0
		},
	}
	eq = &operators.Operator{
		Name:          "=",
		Precedence:    0,
		Associativity: operators.L,
		Args:          2,
		Operation: func(args []float64) float64 {
			if args[0] == args[1] {
				return 1
			}
			return 0
		},
	}
)

func init() {
	operators.Register(and)
	operators.Register(or)
	operators.Register(bitAnd)
	operators.Register(bitOr)
	operators.Register(lt)
	operators.Register(le)
	operators.Register(gt)
	operators.Register(ge)
	operators.Register(eq)
}
